package com.developer.platform.infrastructure.config;

import com.developer.platform.domain.scheduler.SchedulerFactory;
import java.io.IOException;
import org.quartz.Scheduler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * quartz配置
 *
 * @author ：qiaoliang
 * @date ：2021-01-07
 */
@Configuration
public class SchedulerConfig {

  private final SchedulerFactory schedulerFactory;

  public SchedulerConfig(SchedulerFactory schedulerFactory) {
    this.schedulerFactory = schedulerFactory;
  }

  @Bean(name="SchedulerFactory")
  public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    //修改成自己的工厂
    factory.setJobFactory(schedulerFactory);
    factory.setStartupDelay(5);
    return factory;
  }

  /*
   * 通过SchedulerFactoryBean获取Scheduler的实例
   */
  @Bean
  public Scheduler scheduler() throws IOException {
    return schedulerFactoryBean().getScheduler();
  }

}
